import React from 'react'
import { Redirect } from 'react-router-dom'

interface Props {
  getUnauthorized: () => boolean;
  getForbidden: () => boolean;
}

const Authorized: React.FC<Props> = ({ getUnauthorized, getForbidden, children }) => {
  if (getUnauthorized()) return <Redirect to="/login" />
  if (getForbidden()) return <Redirect to="/403" />
  return children as React.ReactElement
}

export default Authorized
